<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>首页</title>
	<link rel="stylesheet" type="text/css" href="../c/aui.css" />
	<style>
		.aui-card-list,
		.aui-card-list li,
		.aui-card-list ul,
		.aui-list .aui-list-item,
		.aui-list {
			background: none;
			border: 0;
			color: #fff;
		}

		#sx-view .aui-list-item-label-icon {
			color: #fff;
			font-size: 0.75rem;
		}

		#sx-view .aui-list-item-input input {
			color: #fff;
		}

		#sx-view .aui-list-item {
			border-bottom: 1px solid #222
		}

		#sx-view .aui-list-item:active {
			background: none
		}

		.img {
			position: relative;
		}

		.img span {
			position: absolute;
			right: 0;
			top: 0;
			height: 2.2rem;
			line-height: 2.2rem;
			padding: 0 1rem;
			border-left: 1px solid #222;
		}

		.img span img {
			width: 1.8rem;
			height: 1.8rem;
			display: inline-block;
			vertical-align: middle;
			margin-right: 0.75rem;
		}

		#sx-view .img span i {
			font-size: 0.6rem;
			margin-left: 0.35rem;
		}

		.sx-btn {
			background: #FE2C55;
			width: 80%;
			text-align: center;
			margin: 0 auto;
			padding: 0.55rem 0;
			border-radius: 0.25rem;
			margin-top: 1rem;
			font-size: 0.75rem;
		}

		.content {
			padding: 0.75rem;
			margin-top: 1rem;
			opacity: 0.7
		}

		.content .h2 {
			font-size: 0.75rem;
			padding-bottom: 0.35rem;
		}

		.content p {
			font-size: 0.7rem;
			padding: 0.15rem;
		}
		.sx-xieyi {
			text-align: center;
			color: #fff;
			font-size: 0.6rem;
			padding: 0.75rem 0;
			opacity: 0.75;
		}

		.sx-xieyi span {
			color: #FFB300;
			padding: 0 0.15rem;
			text-decoration: underline
		}
	</style>
</head>
<body>
	<div class="aui-content" id="sx-view">
		<ul class="aui-list aui-form-list">
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label-icon">
						手机号：
					</div>
					<div class="aui-list-item-input">
						<input type="tel" placeholder="填写已绑定手机号码" value="" id="mobile">
					</div>
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label-icon">
						验证码：
					</div>
					<div class="aui-list-item-input img">
						<input type="tel" placeholder="请输入手机验证码" value="" id="yzm">
						<span tapmode onclick="code()" class="sx-login-code-c">获取验证码</span>
					</div>
				</div>
			</li>
		</ul>
		<div class="sx-btn" tapmode onclick="_loginToken()">绑定并登录</div>
		<p class="sx-xieyi">
			登陆即代表您已阅读并同意<span tapmode onclick="_page('用户协议',1)">用户协议</span>和<span tapmode onclick="_page('隐私政策',2)">隐私政策</span>
		</p>
		<div class="content">
			<div>绑定说明：</div>
			<p>1.绑定手机可作为唯一的登录账户（不可修改）</p>
			<p>2.程度上保障账户安全，比如绑定、提现、实名认证等</p>
			<p>3.我们承诺不会向任何人透露您的个人信息</p>
		</div>
	</div>
</body>
<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript">
	var moduleSMSSDK;
	apiready = function() {
		console.log(_getPrefs('_config').mob)
		if (_getPrefs('_config').mob == 1) {
			moduleSMSSDK = api.require('smssdk');
		}
		api.parseTapmode();
	}
	function _isMobile(phone) {
		if (!(/^1[123456789]\d{9}$/.test(phone))) {
			return false;
		} else {
			return true;
		}
	}
	var isinerval
		// 发送验证码
	function code() {
		if (times) {
			return _msg('不要重复操作')
		}
		_loading();
		var mobile = $('#mobile').val();
		mobile = $api.trimAll($api.trim(mobile));
		if (_isMobile(mobile)) {
			if (_getPrefs('_config').mob == 1) {
				var param = {
					zone: '86',
					phoneNumber: mobile,
					tempCode: _getPrefs('_config').sdkReg_id
				};
				moduleSMSSDK.getTextCode(param, function(ret, err) {
					if (err !== null && err !== undefined && err !== '') {
						_loadingCloes();
						// 错误消息示例：{"msg":"Template not exist.","code":484}
						return _msg(err.msg)
						console.log("Error:\n" + JSON.stringify(err));
					} else {
						_loadingCloes();
						_msg('验证码已发送')
						// 正常消息示例：{"smart":false}
						$('.sx-login-code-c').html('重新获取(120s)');
						times = 120;
						$('.sx-login-code-c').css('color', '#909090');
						isinerval = setInterval("CountDown()", 1000);
						document.getElementById("yzm").focus()
					}
				});
				return;
			}

			_ajax('user/code',function(ret,err){
				_loadingCloes();
				if(ret){
					console.log(JSON.stringify(ret));
					_msg(ret.ret ? ret.ret : ret.err);
					if(ret.ret){
						$('.sx-login-code-c').html('重新获取(120s)');
						times = 120;
						$('.sx-login-code-c').css('color', '#909090');
						isinerval = setInterval("CountDown()", 1000);
						document.getElementById("yzm").focus()
					}else{
						_msg(ret.err)
					}
				}else{
					_alert(JSON.stringify(err));
				}
			},{username:mobile,text:'绑定'})

		} else {
			_msg('手机号码格式错误');
			document.getElementById("mobile").focus()
		}
	}
	var times = 0;

	function CountDown() {
		times--;
		if (times < 1) {
			$('.sx-login-code-c').html('获取验证码');
			$('.sx-login-code-c').css('color', '#fff');
			clearInterval(isinerval);
			return;
		}
		$('.sx-login-code-c').html('重新获取(' + times + 's)');
	}
	var _root = 0;
	function _loginToken() {

		var mobile = $('#mobile').val();
		if(!mobile){
			_msg('请输入手机号码');
			return document.getElementById("mobile").focus()
		}
		if(!_isMobile){
			_msg('手机号码不正确');
			return document.getElementById("mobile").focus()
		}
		var yzm = $('#yzm').val();
		if (!yzm) {
			document.getElementById("yzm").focus()
			return _msg('请输入验证码');
		}

		if(_root){
			return ;
		}
		var json = {};
		var json1 = api.pageParam['data'];
		var json2 = {
			mobile : mobile,
			yzm:yzm
		};
		json = eval('(' + (JSON.stringify(json1) + JSON.stringify(json2)).replace(/}{/, ',') + ')');
		data = json;
		// console.log(JSON.stringify(data))
		// return;
		_root = 1;
		_loading()
		_ajax('user/oauth_mobile', function(ret, err) {
			_loadingCloes();
			if (ret) {
				if(ret.ret){
						_setPrefs('_token', ret.ret);
						// 获取用户资料
					 _ajax('member/info', function(ret, err) {
						 _loadingCloes();
							 if (ret) {
									 if(ret.err){

									 }else{
										 // 重新初始化融云
										 api.execScript({
											 name: 'root',
											 script: 'rongyun_init()'
										 });
										 _setPrefs('_user', ret);
										 api.execScript({
												 name: 'root',
												 frameName: 'oxPlayer_frm',
												 script: 'yuandu();'
										 });
										 _close();
									 }
							 }
					 })
	 				_hone();
	 				console.log(JSON.stringify(ret))
				}else{
					_root = 0;
					return _msg(ret.err);
				}
			} else {
				console.log(JSON.stringify(err))
				_alert(err)
			}
			_root = 0;
		}, data)
	}
</script>

</html>
